const service = require('../services/comment.service');

class CommentController {
  async createComment(ctx, next) {
    let {content, momentId,} = ctx.request.body;
    const {id} = ctx.user
    console.log(id)
    const comment = await service.createComment(momentId  , content, id);
    ctx.body = {
      code: 200,
      data: comment,
      msg: '创建评论成功'
    }
  }
  async reply(ctx, next) {
    let {commentId} = ctx.params;
    let {content, momentId} = ctx.request.body;
    const {id} = ctx.user
    const comment = await service.reply(commentId, content, momentId, id);
    ctx.body = {
      code: 200,
      data: comment,
      msg: '回复成功'
    }
  }
  async updateComment(ctx, next) {
    let {commentId} = ctx.params;
    let {content} = ctx.request.body;
    const comment = await service.updateComment(commentId, content);
    ctx.body = {
      code: 200,
      data: comment,
      msg: '更新评论成功'
    }
  }
  async deleteComment(ctx, next) {
    let {commentId} = ctx.params;
    const comment = await service.deleteComment(commentId);
    ctx.body = {
      code: 200,
      data: comment,
      msg: '删除评论成功'
    }
  }
  async getComments(ctx, next) {
    let {momentId} = ctx.query;//获取url中的参数  query参数的形式是?momentId=1
    const comments = await service.getComments(momentId);
    ctx.body = {
      code: 200,
      data: comments,
      msg: '获取评论成功'
    }
  }
}
module.exports =new CommentController();